#include "Timer.h"

using namespace GalliumEngine;

Timer::Timer(float _duration)
{
	duration = _duration;
	running = true;
	elapsedTime = 0.0f;
	repeats = false;
}

Timer::Timer(float _duration, bool _repeats)
{
	duration = _duration;
	running = true;
	elapsedTime = 0.0f;
	repeats = _repeats;
}

Timer::~Timer()
{
}

void Timer::start()
{
	elapsedTime = 0.0f;
	running = true;
}

void Timer::pause()
{
	running = false;
}

void Timer::unPause()
{
	running = true;
}

void Timer::stop()
{
	elapsedTime = 0.0f;
	running = false;
}

void Timer::setRepeat(bool _repeats)
{
	repeats = _repeats;
}

bool Timer::getRepeat()
{
	return repeats;
}
	
void Timer::update(float delta)
{
	if(running)
	{
		elapsedTime += delta;

		if(elapsedTime > duration)
		{
			OnExpired(EventData());

			if(repeats)
			{
				start();
			}
			else
			{
				stop();
			}
		}
	}
}
